
<?PHP
/**
*
* This function used to add a new Client data.
*/
   include ("../../../Connections/SCMS.php");
   include ("../../../Model/CheckClass.php");
   include ("../../../Model/errorReportClass.php");
   include ("../../../Model/databaseOperationClass.php");
   $Check = new CheckClass();
   $errReport = new errorReportClass();
   $databaseOperation = new databaseOperationClass();

 // Get Post value from ../view/StockViewAdd.php
   $id = $_POST['id'];
   $name = $_POST['name'];
   $phone = $_POST['phone'];
   $email = $_POST['email'];
   $remark = $_POST['remark'];
   $rank = $_POST['rank'];

 //Set report pass.
$reportTo = '../view/clientViewAdd.php';

 //Check value null.
   if($Check->IsNull($name)){  // If null Report error.
       $errReport->errorReport(3, $reportTo);
       exit;
   }
   else if($Check->IsNull($phone)){
       $errReport->errorReport(4, $reportTo);
       exit;
   }
   else if($Check->IsNull($email)){
       $errReport->errorReport(5, $reportTo);
       exit;
   }
   else if($Check->IsNull($remark)){
       $errReport->errorReport(6, $reportTo);
       exit;
   }
   else if($Check->IsNull($rank)){
       $errReport->errorReport(7, $reportTo);
       exit;
   }
   else if($Check->IsNull($id)){
       $errReport->errorReport(12, $reportTo);
       exit;
   }
   //Check value number.
  /*
   else if($Check->notNumber($phone)){
       $errReport->errorReport(9, $reportTo);
       exit;
   }
   //Check value is String
   else if($Check->notString($name)){
       $errReport->errorReport(11, $reportTo);
       exit;
   }*/
	$table = 'client';
	$have = $databaseOperation->checkhave($table,$id);
	if($have){
      $errReport->errorReport(13, $reportTo);
       exit;
   }
   $success = $databaseOperation->insertIntoClient($id, $name, $phone, $email,$remark,$rank);
   $reportSuccess = "../view/clientViewList.php";
if($success){
      $errReport->errorReport(4, $reportTo);
       exit;
   }
   else{
       $errReport->errorReport(2, $reportTo);
       exit;
   }
?>
